package cn.com.shopec.erp.stock.excel.impl;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;

import cn.com.shopec.erp.common.excel.ExcelBaseExport;
import cn.com.shopec.erp.common.utils.DateUtil;
import cn.com.shopec.erp.product.entity.ProductStockExt;

public class ProductStockExcelExport extends ExcelBaseExport {
	
	public ProductStockExcelExport(List<ProductStockExt> data, String fileName, HttpServletResponse response) {
		super(data, fileName, response);
	}

	@Override
	protected Row setColumnMapping(Object data, Row row) {
		ProductStockExt productStock = (ProductStockExt) data;
		int cellIndex = 0;
		Cell cell = row.createCell(cellIndex++);
		cell.setCellValue(productStock.getWhName());

		cell = row.createCell(cellIndex++);
		cell.setCellValue(productStock.getSupName());

		cell = row.createCell(cellIndex++);
		cell.setCellValue(productStock.getProdNo());

		cell = row.createCell(cellIndex++);
		cell.setCellValue(productStock.getCommoNo());

		cell = row.createCell(cellIndex++);
		cell.setCellValue(productStock.getCommoName());

		cell = row.createCell(cellIndex++);
		cell.setCellValue(productStock.getCatName());
		
		cell = row.createCell(cellIndex++);
		cell.setCellValue(productStock.getBrandName());
		
		cell = row.createCell(cellIndex++);
		cell.setCellValue(productStock.getSpecName());
		
		cell = row.createCell(cellIndex++);
		cell.setCellValue(productStock.getProductTotal());
		
		cell = row.createCell(cellIndex++);
		cell.setCellValue(productStock.getQualifiedQuantity());
		
		cell = row.createCell(cellIndex++);
		cell.setCellValue(productStock.getQualifiedQuantity() - 
				(productStock.getPreOccupyQuantity()==null ? 0 : productStock.getPreOccupyQuantity()));
		
		cell = row.createCell(cellIndex++);
		cell.setCellValue(productStock.getDefectiveQuantity());

		cell = row.createCell(cellIndex++);
		cell.setCellValue(DateUtil.formatTimesTampDate(productStock.getUpdateTime()));
		
		return row;
	}

	@Override
	protected List<String> setExcelTitleValue() {
		List<String> title = new ArrayList<String>();
		title.add("仓库名称");
		title.add("供应商名称");
		title.add("货品编号");
		title.add("商品编号");
		title.add("商品名称");
		title.add("分类名称");
		title.add("品牌名称");
		title.add("商品规格");
		title.add("商品数量");
		title.add("良品数量");
		title.add("可用数量");
		title.add("次品数量");
		title.add("更新时间");
		return title;
	}

}
